package live.tag;

import java.io.IOException;
import java.util.Calendar;
import java.util.GregorianCalendar;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import live.common.Format;

import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;



public class WeekDayTag extends TagSupport {

	private static final long serialVersionUID = -9105255904954555811L;
	
	private String strDateTime;
	
	public String getStrDateTime() {
		return strDateTime;
	}

	public void setStrDateTime(String strDateTime) throws JspException {
		this.strDateTime = (String) ExpressionEvaluatorManager.evaluate(
				"strDateTime", strDateTime, Object.class, this,
				this.pageContext);
	}

	@Override
	public int doEndTag() throws JspException {
		// TODO Auto-generated method stub
		Calendar calendar = new GregorianCalendar();
		calendar.setTime(Format.getInstance().stringToDate(strDateTime, "yyyy-MM-dd"));
		int day_of_week = calendar.get(Calendar.DAY_OF_WEEK);
		String day_str="";
		switch(day_of_week){
			case 1:
				day_str="星期日";
				break;
			case 2:
				day_str="星期一";
				break;
			case 3:
				day_str="星期二";
				break;
			case 4:
				day_str="星期三";
				break;
			case 5:
				day_str="星期四";
				break;
			case 6:
				day_str="星期五";
				break;
			case 7:
				day_str="星期六";
				break;
		}
		try {
			pageContext.getOut().write(day_str);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return super.doEndTag();
	}

}
